package com.sesame.service;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.stereotype.Service;

@CommonsLog
@Service
public class TestService {

    @SentinelResource(value = "doSomeThing", blockHandler = "exceptionHandler")
    public String doSomeThing(String str) {
        log.info(str);
        return str;
    }

    // 限流与阻塞处理
    public String exceptionHandler(String str, BlockException ex) {
        log.error( "blockHandler：" + str, ex);
        return "限流 : "+str;
    }





    // 熔断与降级处理
    @SentinelResource(value = "doSomeThing2", fallback = "fallbackHandler")
    public String doSomeThing2(String str) {
        log.info(str);
        throw new RuntimeException("发生异常");
    }

    public String fallbackHandler(String str) {
        log.error("fallbackHandler：" + str);
        return "熔断 : "+str;
    }
}
